import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

/** 
* @author Lql
* @version 创建时间：2017年11月3日 下午1:56:57 
* 类说明 
*/
public class SpeedTest {
	public static void main(String[] args){
		try {
			copyHDFS2Local("64710DC533CB21E64675966D3592EC89715F01DB3687E89C344EC42C09692C51");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void copyHDFS2Local(String encryptfilename) throws IOException {
		try {
			String path2 = "hdfs://192.168.2.220:9000" + "/UserStorage/input" + encryptfilename;
			Path path = new Path(path2);
			Configuration conf = new Configuration();
			FileSystem fileSystem = FileSystem.get(conf);
			if(fileSystem.isFile(path)){
				System.out.print(" is A file !");
			}else {
				System.out.print("noooooooooo!");
			}
			
			
			String path1 = "/home/hadoop/backup/123.mp4";
			String localPath = "/home/lee/hadoop/backup/" + encryptfilename;
			
			InputStream in = fileSystem.open(new Path(path2));
			OutputStream out = new FileOutputStream(localPath);
			IOUtils.copyBytes(in, out, 4096, true);
			System.out.println("文件已成功拷贝");
		} catch (Exception e) {
			System.out.println("文件拷贝失败");
			e.printStackTrace();
			// TODO: handle exception
		}
		
	}
}
